package com.blog.Bard.base.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blog.Bard.base.dao.BardArticleTypeDao;
import com.blog.Bard.base.pojo.BardArticleType;
import com.blog.Bard.common.service.BaseServiceImpl;
import com.blog.Bard.common.util.Pager;

@Service
@Transactional
public class BardArticleTypeServiceImpl extends BaseServiceImpl implements BardArticleTypeService {

	@Autowired
	private BardArticleTypeDao bardArticleTypeDao;

	@Override
	public Pager pageList(Map<String, Object> params) throws Exception {
		Integer pageNo = (Integer)params.get("pageNo");
		Integer pagesize = (Integer)params.get("pagesize");

		StringBuilder sql = new StringBuilder();
		List<Object> args = new ArrayList<Object>();
		
		sql.append(" select * from bardArticleType \n");
		
		return bardArticleTypeDao.getPagerBySql(sql.toString(), pageNo, pagesize, args.toArray());
	}

	@Override
	public void del(Integer id) throws Exception {
		bardArticleTypeDao.deleteById(id);
	}

	@Override
	public void save(BardArticleType t) throws Exception {
		Date now = new Date();
		t.setOptDate(now);
		if(t.getId()==null) {
			Map<String,Object> map = bardArticleTypeDao.getNextSeq();
			Object nextSeq = map.get("nextSeq");
			t.setSeq(Integer.parseInt(nextSeq.toString()));
		}
		bardArticleTypeDao.save(t);
	}

	@Override
	public BardArticleType getOne(Integer id) throws Exception {
		return bardArticleTypeDao.getOne(id);
	}

	@Override
	public List<Map<String, Object>> getAllType() throws Exception {
		return bardArticleTypeDao.queryForList("select * from BardArticleType where status = 1");
	}
	
}
